package com.taptech.doufu.util;

import android.annotation.SuppressLint;
import android.app.Activity;
import android.content.Context;
import android.telephony.TelephonyManager;

import com.taptech.doufu.constant.Constant;

import static android.content.Context.TELEPHONY_SERVICE;

public class DeviceUtil {

	public static int getDeviceTypeAccordingScreen(Context context) {

		final float scale = context.getResources().getDisplayMetrics().density;

		int dpi = Math.round(scale * 160);

		if (dpi <= 0) { // get dpi failed
			return Constant.ScreenSplashType.DEVICE_ANDROID_MDPI;
		} else if (dpi > 0 && dpi <= 120) {
			return Constant.ScreenSplashType.DEVICE_ANDROID_LDPI;
		} else if (dpi > 120 && dpi <= 160) {
			return Constant.ScreenSplashType.DEVICE_ANDROID_MDPI;
		} else if (dpi > 160 && dpi <= 240) {
			return Constant.ScreenSplashType.DEVICE_ANDROID_HDPI;
		} else {
			return Constant.ScreenSplashType.DEVICE_ANDROID_XDPI;
		}
	}


	/**
	 * 获取设备ID
	 * @return
	 */
	@SuppressLint("MissingPermission")
	public static String getDeviceID(Activity activity) {
		try {
			TelephonyManager telephonyMgr = (TelephonyManager) activity.getSystemService(TELEPHONY_SERVICE);
			return  telephonyMgr.getDeviceId();
		} catch (Exception e) {
			return "";
		}

	}

	/**
	 * 判断是否是模拟器
	 * @return
	 */
	public static boolean isSimulator() {
		if ("unknown".equals(android.os.Build.SERIAL)) {
			return true;
		}else{
			return false;
		}
	}
}
